//
//  Gccfg.cpp
//  ConstructGccfg2.0
//
//  Created by Bryce Holton on 12/4/12.
//  Copyright (c) 2012 Bryce Holton. All rights reserved.
//

#include "Gccfg.h"
#include "FileParse.h"

Gccfg::Gccfg(string graphName, vector<string> &fileNames)
{
    name = graphName;
    
    for (unsigned int i = 0; i < fileNames.size(); i++)
    {
        FileParse parser(fileNames[i]);
        ProgramFunction *function;
        
        while ( ( function = parser.ParseFunction() ) != NULL )
        {
            functions.push_back(function);
        }
    }
}
Gccfg::~Gccfg()
{
    for (unsigned int i = 0; i < functions.size(); i++)
    {
        delete functions[i];
    }
    functions.clear();
}
void Gccfg::GenerateGraph()
{
    unsigned int i;
    
    // First we generate Global Cfg
    
    
    // Second we generate Gccfg.
    for (i = 0; i < functions.size(); i++)
    {
        // First Sort the blocks in a function into loops and cfgs
        functions[i]->SeparateLoopBlocksFromFunctionBlocks();
        // Second create unique entry and exit blocks for each function component.
        
        // Third Normalize each component.
        
        // Fourth Find the convergence point for every condition block.
        
        // Fifth build a hierarchy for each compoenent.
        
    }
    // Finally, connect all the hierarchies and clean up graph.
}
